#include "gdn/RenderImage.h"

#include "gdn/Utility.h"

namespace gdn
{
	RenderImage::RenderImage()
	{
	}

	RenderImage::RenderImage( const RenderImage& toCopy )
	{
		( * this ) = toCopy;
	}

	void RenderImage::Create( const Vector2i& theSize )
	{
		renderImage.Create( theSize.x, theSize.y );
		Clear();
	}

	Vector2< unsigned int > RenderImage::GetSize() const
	{
		return Vector2< unsigned int >( renderImage.GetWidth(), renderImage.GetHeight() );
	}

	void RenderImage::Clear()
	{
		renderImage.Clear( sf::Color::Black );
	}

	void RenderImage::Draw( const Sprite& draw )
	{
		renderImage.Draw( draw.sprite );
	}

	void RenderImage::Draw( const Text& draw )
	{
		renderImage.Draw( draw.text );
	}

	void RenderImage::Display()
	{
		renderImage.Display();
	}

	Image& RenderImage::GetImage() const
	{
		//#warning VERY buggy.
		image.image.Create( GetSize().x, GetSize().y );
		image.image.Copy( renderImage.GetImage(), 0, 0, sf::IntRect( 0, 0, GetSize().x, GetSize().y ) );
		//std::cout << image.image.GetWidth() << "x" << image.image.GetHeight() << " vs " << GetSize().x << "x" << GetSize().y << std::endl;
		return image;
	}

	RenderImage& RenderImage::operator= ( const RenderImage& toCopy )
	{
		gdn::Vector2< unsigned int > size = toCopy.image.GetSize();
		renderImage.Create( size.x, size.y );

		sf::Sprite sprite;
		sprite.SetImage( toCopy.image.image );

		renderImage.Draw( sprite );
		renderImage.Display();

		return ( * this );
	}
}
